<template>
  <math>
    <mtr>
      <mtd>
        <mrow v-for="(v, i) in numfirst" :key="'1mathAdd'+i">
          <mn v-text="v"></mn>
          <mo v-if="i !== numfirst.length - 1">+</mo>
        </mrow>
        <mo v-if="!shownum(num.length-12)">......</mo>
        <mrow v-for="(v, i) in numend" :key="'2mathAdd'+i">
          <mn v-text="v"></mn>
          <mo v-if="i !== numend.length - 1">+</mo>
        </mrow>
        <mo>=</mo>
        <mn v-text="andNum"></mn>
      </mtd>
    </mtr>
  </math>
</template>

<script lang="ts">
import { Component, Vue, Watch, Provide, Prop } from "vue-property-decorator";

@Component({
  name: "mathAdd"
})
export default class Add extends Vue {
  @Provide() andNum: number = 0;
  @Provide() numend: number[] = [];
  @Provide() numfirst: number[] = [];
  @Prop() private num!: number[];
  @Watch("num")
  onChildChanged(v: number[]) {
    this.init(this.num);
  }
  init(data: number[]) {
    let i = 0;
    data.map(v => {
      this.andNum += v;
      if (i < 10) {
        this.numfirst.push(v);
      }
      if (data.length > 10 && i > 9 && i > data.length - 11) {
        this.numend.push(v);
      }
      i++;
    });
  }
  shownum(i: number) {
    if (this.num.length < 20) {
      return true;
    } else {
      if (i < 10 || i > this.num.length - 12) {
        return true;
      }
    }
    return false;
  }
  mounted(): void {
    this.andNum = 0;
    this.init(this.num);
  }
}
</script>

<style lang="scss" scoped>
</style>
